<html>
<head>
  <title>How To Setup MSP430 Ports...</title>
</head>

<body>

<!-- BEGIN LAB DESCRIPTION -->

<font face="Arial">
<!------------------------------------------------------------------------------------>
<a name="HowToSetupPorts">
<h2>How To Setup MSP430 Ports...</h2>
</a>

<p>The most straightforward form of input/output of the MSP430 is through
the digital input/output ports.  The following table summarizes the control
registers for the ports of the MSP430F2274:

<p><table border=1>
<tr>
  <td><b>P1DIR</b></td>
  <td width="220">Port P1 Direction</td>
  <td>Clearing a bit configures a pin as an input while setting a bit
      configures a pin for output.</td>
</tr>

<tr>
  <td><b>P1REN</b></td>
  <td>Port P1 Resistor Enable</td>
  <td>Setting a bit activates an internal pull-up/pull-down
      resistor on a pin.  The corresponding bit in the <b>P1OUT</b>
      register selects pull-up if set to one or pull-down if
      set to zero.</td>
</tr>

<tr>
  <td><b>P1SEL</b></td>
  <td>Port P1 Selection</td>
  <td>Clearing a bit configures a pin as a digital input/output (GPIO),
      while setting a bit selects an alternative function.</td>
</tr>

<tr>
  <td><b>*P1IE</b></td>
  <td>Port P1 Interrupt Enable</td>
  <td>Setting a bit enables an interrupt when the input pin changes.</td>
</tr>

<tr>
  <td><b>*P1IES</b></td>
  <td>Port P1 Interrupt Edge Select</td>
  <td>Interrupts can be generated on either a positive edge (low to high)
      or negative edge (high to low) change of an input pin.</td>
</tr>

<tr>
  <td><b>*P1IFG</b></td>
  <td>Port P1 Interrupt Flag</td>
  <td>A bit is set when the selected transition has been detected on the input.</td>
</tr>

</table>

<p>*Note: Ports P3 and P4 do not have interrupt capability.

<p>The following assembly code can be used to setup the eZ430X ports:

<blockquote><pre>;------------------------------------------------------------------------------
;    General initialization of eZ430X board
;------------------------------------------------------------------------------
;
;                       MSP430F2274
;                    -----------------
;                /|\|         XIN P2.6|-->LED_D
;                 | |        XOUT P2.7|-->LED_C
;                 --|RST              |
;                   |                 |
;         RED LED-->|P1.0         P2.0|<--SW1 (pull-up)
;       GREEN LED-->|P1.1         P2.1|<--SW2 (pull-up)
;    eZ430 BUTTON-->|P1.2         P2.2|<--SW3 (pull-up)
;                   |             P2.3|<--SW4 (pull-up)
;                   |             P2.4|-->LCD BACKLIGHT
;                   |                 |
;                   |             P2.6|-->LED_D
;                   |             P2.7|-->LED_C
;                   |             P3.3|-->LED_B
;                   |             P4.6|-->LED_A
;                   |                 |
;                   |             P4.5|-->BUZZER (P4SEL.5=1)
;
eZ430X_init:
        mov.w   #WDTPW+WDTHOLD,&WDTCTL   ; Stop WDT

;       LCD Reset
        bis.b   #0x01,&P3DIR             ; LCD Reset
        bic.b   #0x01,&P3OUT
        bis.b   #0x01,&P3OUT

;       MSP430 Clock - Set DCO to 8 MHz:
;       mov.b   &CALBC1_8MHZ,&BCSCTL1    ; Set range
;       mov.b   &CALDCO_8MHZ,&DCOCTL     ; Set DCO step + modulation

;       eZ430 LED's
        bis.b   #0x03,&P1DIR             ; eZ430 LED's
        bic.b   #0x03,&P1OUT

;       eZ430 push button
        bic.b   #0x04,&P1DIR             ; eZ430 push button
        bis.b   #0x04,&P1IE              ; Interrupt Enable in P1.2
        bis.b   #0x04,&P1IES             ; P1.2 Interrupt flag high-to-low transition
        bic.b   #0x04,&P1IFG             ; P1.2 IFG Cleared
        bis.b   #0x04,&P1REN             ; P1.2 Pull-Up/Down Resistor enable

;       eZ430X push buttons
        bic.b   #0x0f,&P2SEL             ; eZ430X push buttons
        bic.b   #0x0f,&P2DIR             ; Configure P2.0-3 as Inputs
        bis.b   #0x0f,&P2OUT             ; pull-ups
        bis.b   #0x0f,&P2IES             ; h to l
        bis.b   #0x0f,&P2REN             ; Enable pull-ups

;       eZ430X LEDs
        bis.b   #LED_A,&P4DIR            ; LED_A P4.6
        bic.b   #LED_A,&P4OUT 
        bis.b   #LED_B,&P3DIR            ; LED_B P3.3
        bic.b   #LED_B,&P3OUT
        bic.b   #LED_C+LED_D,&P2SEL
        bis.b   #LED_C+LED_D,&P2DIR      ; LED_C (P2.7) & LED_D (P2.6)
        bic.b   #LED_C+LED_D,&P2OUT

;       eZ430X buzzer
        bis.b   #0x20,&P4DIR             ; P4.5 output (buzzer)
        bis.b   #0x20,&P4SEL             ; P4.5 uses TB2
        ret</pre></blockquote>

<p>See Digital Input, Output, and Displays, MMB pgs. 207-224.

<!-- END LAB DESCRIPTION -->

</body>
</html>
